package constant.milk.cashbook.sms.parser;

import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import constant.milk.cashbook.bean.SmsInputData;
import constant.milk.cashbook.util.MilkUtil;

public class SmsOutMoney5 
{
	private int smsType; 
//	private boolean flagATM = false;
//	private boolean flagHalbu = false;
//	private String halbuMonth = "0";
//	
//	private boolean FLAG = true;
	private boolean available = false;
//	
//	private boolean outmoneyFlag = false;
//	
//	//1:check 2:credit
	private int checkcreditFlag = 0;
//	
	private final int CHECK = 1;
	private final int CREDIT = 2;
//	
	private String message;
	private SmsInputData data;
//	
	private String date;
	
	public SmsOutMoney5(){};
	
	public SmsOutMoney5(SmsInputData data, String message, String date, int smsType, int checkcreditFlag)
	{
		this.data = data;
		this.message = message;
		this.date = date;
		this.smsType = smsType;
		this.checkcreditFlag = checkcreditFlag;
		
		outMoney();
	}
	
	public boolean getAvailable()
	{
		return available;
	}
	
	public SmsInputData getData()
	{
		return data;
	}
	
	public int getSmsType()
	{
		return smsType;
	}
	
	private void outMoney()
	{
		if ( (data.getName().equalsIgnoreCase("DGB")) )
		{
			/*
			 * DGB 03/07 21:59
				08013**0272
				출금 2,500
				잔액 1,633,954
				대백마트
				
				DGB 05/06 14:20
				17408*21931
				출금 36,000
				급식비
				
				DGB 05/31 02:26
				17408*21931
				출금 13,690
				잔액 263,068
				가스1305
			 */
			Pattern pName = Pattern.compile("(\\d{1,8}\\*{1,5}\\d{1,8})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금\\s*\\n*\\s*\\n*(\\d*,*\\d*,*\\d*,*\\d)\\s*\n*\\s*\\n*");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액\\s*\\n*\\s*\\n*-*\\d*,*\\d*,*\\d*,*\\d\\s*\n*\\s*\\n*(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo3 = Pattern.compile("출금\\s*\\n*\\s*\\n*\\d*,*\\d*,*\\d*,*\\d\\s*\n*\\s*\\n*(.+$)");
			Matcher mMemo3 = pMemo3.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("DGB" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)).replaceAll("\\n", "").trim());
					data.setMemo2((mMemo.group(1)).replaceAll("\\n", "").trim());
					data.setMemo3((mMemo.group(1)).replaceAll("\\n", "").trim());
					data.setMemo4((mMemo.group(1)).replaceAll("\\n", "").trim());
				}
			}
			else if (mMemo3.find()) 
			{
				for (int i=0; i<mMemo3.groupCount(); i++) 
				{
					data.setMemo1((mMemo3.group(1)).replaceAll("\\n", "").trim());
					data.setMemo2((mMemo3.group(1)).replaceAll("\\n", "").trim());
					data.setMemo3((mMemo3.group(1)).replaceAll("\\n", "").trim());
					data.setMemo4((mMemo3.group(1)).replaceAll("\\n", "").trim());
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("수협카드") ) )
		{
			/*
				[수협카드] ***님
				02월05일17:49
				맘스치킨구룡포
				84,000원사용
				잔액:***,***원
				
				[수협카드]이범희님 06/20 대성산업( 70,000원 사용(누적액)358,670원 
			 */
			
			Pattern pName = Pattern.compile("\\]\\s*(.{1,5})님");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2})월(\\d{1,2})일");
			Matcher mDate = pDate.matcher(message);
			Pattern pDate2 = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate2 = pDate2.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}월\\d{1,2}일\\d{1,2}:\\d{1,2}\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d원사용");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d{1,2}/\\d{1,2}\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("수협카드" + "(" + mName.group(1) + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR) + mDate.group(1) + mDate.group(2));
				}
				
				available = true;
			}
			else if (mDate2.find()) 
			{
				for (int i=0; i<mDate2.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR) + mDate2.group(1).replaceAll("/", ""));
				}
				
				available = true;
			}
			else if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		if ( (data.getName().equalsIgnoreCase("수협알림") ) )
		{
			/*
				[수협알림]
				홍길동님
				[05501049***]
				004(DTPIA)민출금
				110,000원
			 */
			
			Pattern pName = Pattern.compile("(\\d{1,}\\*{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
//			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
//			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\*\\]\\s+(.+\\s*.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("수협" + "(" + mName.group(1).replaceAll("\\*", "") + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
//			if (mDate.find()) 
//			{
//				for (int i=0; i<mDate.groupCount(); i++) 
//				{
//					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
//				}
//				
//				available = true;
//			}
//			else 
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("우체국")) )
		{
			/*
			 * 우체국 정선재님.10,500원.승인.09/18.21:18:36.잔액663,417원로사리오	// 체크카드결제
			 * 
			 * 우체국 이미나님.3,600원.승인.01/23.14:37:13.잔액100,970원롯데쇼핑(주)롯데슈퍼홍은점
			 * 
			 * 우체국 함우상님 23,000원. 승인. 01/24.20:36:28.용봉파불고기
			 * 
			 * 우체국,14:00
				603********601
				출금30,000원
				잔액6,875원
				현대카드				// 그냥 출금
				
				우체국,21:18
				613********601
				출금90,000원
				잔액103,925원
				ATM출금
				
				우체국,19:58?
				601********731
				출금32,700원
				잔액10,954원
				삼성（주）바이더
				
			 */
			
			Pattern pName = Pattern.compile("(\\d{2,}\\*{3,}\\d{2,})\\s+출금");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("우체국\\s+(.+)님");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액-*\\d*,*\\d*,*\\d*,*\\d원\\s*(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d{1,2}:\\d{1,2}:\\d{1,2}.(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("우체국" + "(" + mName.group(1) + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName("우체국" + "(" + mName2.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					Pattern pMemo3 = Pattern.compile("ATM출금");
					Matcher mMemo3 = pMemo3.matcher(mMemo.group(1));
					
					if (mMemo3.find())
					{
						data.setMemo1("현금 출금");
						data.setMemo2("현금 출금");
						data.setMemo3("현금 출금");
						data.setMemo4("현금 출금");
						
						smsType = SmsParser.OUT_ATM_SMS;
					}
					else
					{
						data.setMemo1((mMemo.group(1)));
						data.setMemo2((mMemo.group(1)));
						data.setMemo3((mMemo.group(1)));
						data.setMemo4((mMemo.group(1)));
					}
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("한국투자")) )
		{
			/*
			 * [한국투자]
				김재은님
				8011****-21
				18,000원
				삼성카드체크출금
				(잔액: 177,600원)
				
				[한국투자] 10:36
				7874****-21
				이체출금
				200,000원
				농협 김은옥
				
				[한국투자] 01:35
				8017****-21
				이체출금
				100,000원
				아무개
			 */
			
			Pattern pName = Pattern.compile("(\\d{2,}\\*{2,}-\\d{2,})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s*.+)\\s+\\(잔액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("한국투자" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("메리츠CMA")) )
		{
			/*
			 * [메리츠CMA]정광열님  ****-****-* *
				￦10,000 출금완료 잔액 ￦97,240
				
				[메리츠CMA]남상남님01/20 13:22 2253****16출금￦130,000 잔액 ￦2,208,972
				
				[메리츠CMA]홍길동님05/16 07:35
				2293****16출금￦500,000 잔액￦56,092
			 */
			
			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.{2,})\\s*출금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("출금\\s*.(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("(출금\\s*.\\d*,*\\d*,*\\d*,*\\d)\\s+");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("메리츠CMA" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("JBCard")) )
		{
			/*
			 * [JBCard]0040
				3,550원
				일시불승인
				11/13 16:28
				훼미리마트전주행복점
				
				[JBCard]4802
				4,500원
				일시불승인
				01/23 20:52
				이디아커피효자휴먼시
				
				[JBCard] 7897
				56,640원
				일시불승인
				03/11 11:09
				누계36만원
				olleh모바일자동
				
				[JBCard] 0295
				10,000원
				일시불승인
				05/15 09:36
				누계8만원
				동부화재해상보험(주)
			 */
			
			Pattern pName = Pattern.compile("\\[JBCard\\]\\s*(\\d{4})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+누계.+\\s+(.+$)");
			Matcher mMemo2 = pMemo2.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("JBCard" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("신협카드")) )
		{
			/*
			 * 신협카드]02/04 18:46
				강지승님
				홈플러스테스
				5,500원승인
				잔액15,161원
			 */
			Pattern pName = Pattern.compile("신협카드\\]\\d{1,2}/\\d{1,2}\\s+\\d{1,2}:\\d{1,2}\\s+(.{1,5})님");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("님\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("신협카드" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("신협")) )
		{
			/*
			 * 신협)132-***-*91246 11/27 06:26 출금 81,055원 BC779258872    잔액2,059,986원
			 * 
			 * 신협)03239-**-*07707 03/24 14:50 출금 17,160원 제로마트       잔액1,876,194원
				신협)03239-**-*07707 03/27 10:41 출금 3,900원 파리바게뜨아주 잔액1,434,544원 
			 */
			Pattern pName = Pattern.compile("신협\\)(.{12,17})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s*.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("신협" + "(" + mName.group(1).replaceAll("-", "").replaceAll(" ", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("경남")) )
		{
			/*
			 * 경남 11/23 05:01 516210xxx810 출금 경남 비씨/779\41,370       잔액359,685
				경남 11/26 09:02 516210xxx810 출금 경남 신한0069\180,420      잔액1,126,445
				
				경남 04/09 08:09 689210xxx469 입금 신한 신정애 \1,000,000 잔액1,483,109
				경남 04/27 00:37 689210xxx469 출금 썬빌리지편의점 \2,300 잔액40,718

			 */
			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.{12})\\s+출금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)\\s+잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("출금\\s+(.+)\\\\d*,*\\d*,*\\d*,*\\d");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("경남" + "(" + mName.group(1).replaceAll("-", "").replaceAll(" ", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("현대스위스")) )
		{
			/*
			 * 현대스위스 심소라님 3,900원 승인(계좌잔액588,165원)01/13 08:42T-money택시
			 * 
			 */
//			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.{12})\\s+출금");
//			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
//			if (mName.find())
//			{
//				for (int i=0; i<mName.groupCount(); i++) 
//				{
					data.setName("현대스위스");
//				}
//			}
//			else
//			{
//				available = false;
//				return;
//			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("스쿨")) )
		{
			/*
			 * [스쿨.승인]3,300원.OOO님.잔액171610.
				11/28 07:28
				(주)코리아세븐S고려대역점
			 */
//			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.{12})\\s+출금");
//			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
//			if (mName.find())
//			{
//				for (int i=0; i<mName.groupCount(); i++) 
//				{
					data.setName("스쿨");
//				}
//			}
//			else
//			{
//				available = false;
//				return;
//			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("Tbroad한빛")) )
		{
			/*
			 * [Tbroad한빛]01월SMS청구서￦35,400☞21일출금예정_01/07기준www.tbroad.com확인
			 */
//			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.{12})\\s+출금");
//			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("￦(\\d*,*\\d*,*\\d*,*\\d)☞");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2})일출금예정_(\\d{1,2})/");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("(\\d{1,2}월SMS청구서)");
			Matcher mMemo = pMemo.matcher(message);
			
//			if (mName.find())
//			{
//				for (int i=0; i<mName.groupCount(); i++) 
//				{
					data.setName("Tbroad한빛");
//				}
//			}
//			else
//			{
//				available = false;
//				return;
//			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
//			if (date != null && date.length() > 0)
//			{
//				data.setDate(date);
//			} 
//			else 
			if (mDate.find()) 
			{
				String day = mDate.group(1);
				
				if (mDate.group(1).length() == 1)
				{
					day = "0" + mDate.group(1);
				}
				
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+mDate.group(2)+day);
				}
			}
//			else
//			{
//				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
//			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1("Tbroad한빛 " + (mMemo.group(1)));
					data.setMemo2("Tbroad한빛 " + (mMemo.group(1)));
					data.setMemo3("Tbroad한빛 " + (mMemo.group(1)));
					data.setMemo4("Tbroad한빛 " + (mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("씨티")) )
		{
			/*
			 * 씨티  11/22  17:51  435-24***262  지급  52,120  적요Lgu2908
			 */
			Pattern pName = Pattern.compile("(\\d{1,5}-\\d{1,5}\\*{1,5}\\d{1,5})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("지급\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("지급\\s+\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("씨티" + "(" + mName.group(1).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1("지급 " + (mMemo.group(1)));
					data.setMemo2("지급 " + (mMemo.group(1)));
					data.setMemo3("지급 " + (mMemo.group(1)));
					data.setMemo4("지급 " + (mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("하나대투")) )
		{
			/*
			 * 하나대투.김윤상님.체크카드출금.
				\6,000.잔액.\441,791.
			 */
//			Pattern pName = Pattern.compile("(\\d{1,5}-\\d{1,5}\\*{1,5}\\d{1,5})");
//			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)\\.잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
//			Pattern pMemo = Pattern.compile("지급\\s+\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");
//			Matcher mMemo = pMemo.matcher(message);
			
//			if (mName.find())
//			{
//				for (int i=0; i<mName.groupCount(); i++) 
//				{
					data.setName("하나대투");
//				}
//			}
//			else
//			{
//				available = false;
//				return;
//			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(MilkUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//			if (mMemo.find()) 
//			{
//				for (int i=0; i<mMemo.groupCount(); i++) 
//				{
					data.setMemo1("체크카드출금 ");
					data.setMemo2("체크카드출금 ");
					data.setMemo3("체크카드출금 ");
					data.setMemo4("체크카드출금 ");
//				}
//			}
//			else
//			{
//				available = false;
//				return;
//			}
			
			available = true;
		}
		
		if (data.getName() == null || data.getName().equalsIgnoreCase(""))
		{
			SmsOutMoney6 som6 = new SmsOutMoney6(data, message, date, smsType, checkcreditFlag);
			this.data = som6.getData();
			this.smsType = som6.getSmsType();
			this.available = som6.getAvailable();
		}
		if (data.getDate() == null || data.getDate().equalsIgnoreCase(""))
		{
			SmsOutMoney6 som6 = new SmsOutMoney6(data, message, date, smsType, checkcreditFlag);
			this.data = som6.getData();
			this.smsType = som6.getSmsType();
			this.available = som6.getAvailable();
		}
		if (data.getMoney() == null || data.getMoney().equalsIgnoreCase(""))
		{
			SmsOutMoney6 som6 = new SmsOutMoney6(data, message, date, smsType, checkcreditFlag);
			this.data = som6.getData();
			this.smsType = som6.getSmsType();
			this.available = som6.getAvailable();
		}
		if ( (data.getMemo1() == null) || (data.getMemo1().equalsIgnoreCase("")) 
				&& ( (data.getMemo2() == null) || (data.getMemo2().equalsIgnoreCase("")) )
				&& ( (data.getMemo3() == null) || (data.getMemo3().equalsIgnoreCase("")) )
				&& ( (data.getMemo4() == null) || (data.getMemo4().equalsIgnoreCase("")) ) )
		{
			SmsOutMoney6 som6 = new SmsOutMoney6(data, message, date, smsType, checkcreditFlag);
			this.data = som6.getData();
			this.smsType = som6.getSmsType();
			this.available = som6.getAvailable();
		}
		if (data.getName() == null || data.getName().equalsIgnoreCase("") 
				|| data.getDate() == null || data.getDate().equalsIgnoreCase("") 
				|| data.getMoney() == null || data.getMoney().equalsIgnoreCase("")
				|| ( data.getMemo1() == null || data.getMemo1().equalsIgnoreCase("") 
				&& data.getMemo2() == null || data.getMemo2().equalsIgnoreCase("")
				&& data.getMemo3() == null || data.getMemo3().equalsIgnoreCase("")
				&& data.getMemo4() == null || data.getMemo4().equalsIgnoreCase("") ) )
		{
			this.available = false;
			return;
		}
	}
}
